import _ from 'lodash';
import PubSub from 'pubsub-js';
import $ from 'jquery';

function component() {
    //var element = document.createElement('button');
    var $element = $("<button></button>");
    // Lodash（目前通过一个 script 脚本引入）对于执行这一行是必需的
    //element.innerHTML = _.join(['Hello', 'webpack'], ' ');
    $element.text("hello webpack and pubsub");
    $element.bind("click",function(e){
        //console.info(e);
        //异步发送cat消息，也可以同步发送消息-publishSync
        PubSub.publish('cat', {
            name: "xiaogang",
            date: new Date()
        });
    });
    return $element;
}

function _for(){
    console.info(PubSub);
    _.forEach({ 'a': 1, 'b': 2 }, function (value, key) {
        console.log(key+":"+value);
    });
}
$(this).ready(function(){
    $('body').append(component());
});

_for();

var catHandler = function (msg, data) {
    console.log(msg, data);
};
//订阅cat消息,使用catHandler回调处理
var token = PubSub.subscribe('cat', catHandler);